package com.wb.dao;

import java.util.List;

import org.hibernate.Session;

import com.wb.model.User;
import com.wb.util.HibernateUtil;

public class UserDao {

	 
	 public void save(User user){
		 Session session = HibernateUtil.getSessionFactory().getCurrentSession(); 
		 session.beginTransaction();
		 session.save(user);
		 session.getTransaction().commit();
	 }
	 public void update(User user){
		 Session session = HibernateUtil.getSessionFactory().getCurrentSession(); 
		 session.beginTransaction();
		 session.update(user);
		 session.getTransaction().commit();
	 }
	public List listUsers(){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession(); 
		 session.beginTransaction();
		 List result = session.createQuery("from User").list();
		 session.getTransaction().commit();
		 return result;
	}
	
	public User get(int id){
			Session session = HibernateUtil.getSessionFactory().getCurrentSession(); 
		 session.beginTransaction();
		User u = (User) session.load(User.class, id);
		 session.getTransaction().commit();
		 return u;
	}
	public void delete(User u){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession(); 
		 session.beginTransaction();
		session.delete(u);
		 session.getTransaction().commit();
	}
	 

}
